//
//  RBVideoFullScreenVC.m
//  RBVideoPlayer
//
//  Created by Lan on 2019/2/25.
//  Copyright © 2019 SummerTea. All rights reserved.
//

#import "RBVideoFullScreenVC.h"
#import "UIViewController+RBMediaAdd.h"

@interface RBVideoFullScreenVC ()

@property(nonatomic, assign) BOOL appeared;
@property(nonatomic, copy) void(^viewDidAppearBlock)(UIView *containerView);
@property(nonatomic, strong)IBOutlet UIView *containerView;

@end

@implementation RBVideoFullScreenVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    self.forcePortrait = NO;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
    if (self.viewWillDisapperBlock)
    {
        self.viewWillDisapperBlock();
        self.viewWillDisapperBlock = nil;
    }
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    if (!self.appeared)
    {
        self.appeared = YES;
        if (self.viewDidAppearBlock)
        {
            self.viewDidAppearBlock(self.containerView);
        }
    }
}

- (void)showWithVC: (UIViewController *)vc viewAppeared: (void(^)(UIView *view))viewDidAppearBlock
{
    self.viewDidAppearBlock = viewDidAppearBlock;
//    self.providesPresentationContextTransitionStyle = YES;
//    self.definesPresentationContext = YES;
    self.modalPresentationStyle = UIModalPresentationFullScreen;
    [vc presentViewController:self animated:NO completion:nil];

}

#pragma mark - Rotation

-(BOOL)shouldAutorotate
{
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    if (self.preferredInterfaceOrientation == UIInterfaceOrientationLandscapeRight || self.preferredInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        return self.preferredInterfaceOrientation;
    }
    else
    {
        return UIInterfaceOrientationLandscapeRight;
    }
}


@end
